<template>
  <el-form-item label="播放器宽度">
    <el-input v-model="localData.width" placeholder="请输入百分比或像素值" />
  </el-form-item>
  <el-form-item label="播放器高度">
    <el-input v-model="localData.height" placeholder="请输入百分比或像素值" />
  </el-form-item>
  <el-form-item label="自动播放">
    <el-switch v-model="localData.autoplay" />
  </el-form-item>
  <el-form-item label="封面地址绑定">
    <el-cascader :props="CascaderProps" :options="attrList" v-model="localData.cover" placeholder="请选择属性" filterable clearable :show-all-levels="false">
      <template #default="{ data: opt }">
        <span>{{ `${opt.entityDesc}(${opt.entityName})` }}</span>
      </template>
    </el-cascader>
  </el-form-item>
</template>

<script>
export default {
  name: 'VideoPlayerConfig',
  props: {
    data: {
      type: Object,
      default: () => {}
    },
    attrList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      localData: {},
      CascaderProps: {
        value: 'entityName',
        label: 'entityDescName',
        children: 'childList',
        emitPath: false
      }
    };
  },
  watch: {
    data: {
      handler(newVal) {
        if (newVal) {
          this.localData = newVal;
        }
      },
      deep: true,
      immediate: true
    },
    localData: {
      handler(newVal) {
        this.$emit('update:data', newVal);
      },
      deep: true
    }
  }
};
</script>
